package com.zzjson.activemq;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.util.Enumeration;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.activemq</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年11月20日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class JmsTopicProducer {
	public static void main(String[] args) {
		ConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory("tcp://116.62.221.6:61616");
		Connection connection = null;
		try {
			connection = mqConnectionFactory.createConnection();
			connection.start();
			Enumeration jmsxPropertyNames = connection.getMetaData().getJMSXPropertyNames();
			while (jmsxPropertyNames.hasMoreElements()) {
				String name = (String) jmsxPropertyNames.nextElement();
				System.out.println(name);
			}
			Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
			//创建目的地
			Destination destination = session.createTopic("myTopic");
			//创建发送者
			MessageProducer producer = session.createProducer(destination);
			//producer.setDeliveryMode(DeliveryMode.PERSISTENT);
			//创建需要发送的消息
			TextMessage hello_world = session.createTextMessage("topic message");
			producer.send(hello_world);
			session.commit();
			session.close();

		} catch (JMSException e) {
			e.printStackTrace();
		} finally {
			if (connection != null) {
				try {
					connection.close();
				} catch (JMSException e) {
					e.printStackTrace();
				}

			}
		}
	}
}